*********************************************************************************
*	Polarization Between the Rich and the Poor?									*
*	The Dynamics and Structure of Redistributive Preferences in a Comparative	*
*	Perspective																	*
*																				*
*	Xavier Romero-Vidal, University of Cambridge								*
* 	Steven M. Van Hauwaert, University of Surrey & Radboud University Nijmegen	*
*********************************************************************************

* The original dataset is panneled and has the following variables, directly exported from MCalc
	* year
	* country
	* class
	* mood

* Create a unique country-class identifier

gen country_class = string(country,"%2.0f") + string(class,"%2.0f")
destring country_class, replace
label variable country_class "Unique country-class identifier"

// Figure 1: Redistributive preferences for all

* Calculate the standardised measures around the country-means in the panneled dataset:

sort country
by country: egen mean_mood = mean(mood) if class == 0
label variable mean_mood "Mean mood (all citizens), per country"
by country: egen sd_mood = sd(mood) if class == 0
label variable sd_mood "Std. dev. mood (all citizens), per country"

sort country_class
by country_class: gen std_mood = (mood-mean_mood)/sd_mood if class == 0
label variable std_mood "Standardised mood (all citizens), per country class"

* Visualise the overall measures
twoway (line std_mood year, lpattern(solid)) if class == 0, ytitle(Standardised redistributive preferences, size(vsmall)) by(country) scheme(plottig) legend(size(vsmall) position(6)) xlabel(1975(5)2015, angle(45) labsize(vsmall)) 


// Table 2: Descriptive statistics (panelled dataset)

tabstat mood if class == 0, by(country) stat(n mean sd) columns(stat)

pwcorr std_fr_all std_de_all std_gb_all std_nl_all std_no_all std_se_all std_ch_all
alpha std_fr_all std_de_all std_gb_all std_nl_all std_no_all std_se_all std_ch_all, detail item
factor std_fr_all std_de_all std_gb_all std_nl_all std_no_all std_se_all std_ch_all


// Figure 2: Redistributive preferences, by income group and country

sort country
by country: egen mean_classmood = mean(mood) if class != 0
label variable mean_classmood "Mean mood, per country across income groups"
by country: egen sd_classmood = sd(mood) if class != 0
label variable sd_classmood "Std. dev. mood, per country across income groups"

sort country_class
by country_class: gen std_classmood = (mood-mean_classmood)/sd_classmood if class != 0
label variable std_classmood "Standardised mood, per country across income groups"

* Visualise the class measures

twoway (line std_classmood year if class==1, lpattern(solid)) (line std_classmood year if class==2, lpattern(solid)) (line std_classmood year if class==3, lpattern(solid)), ytitle(Standardised redistributive preferences, size(vsmall)) by(country) scheme(plottig) legend(size(vsmall) position(6) label(1 "Preferences of low-income groups") label(2 "Preferences of middle-income groups") label(3 "Preferences of high-income groups")) xlabel(1975(5)2015, angle(45) labsize(vsmall)) 


// Table 4: Descriptive statistics for redistributive preferences, by income and country

tabstat mood if class == 1, by(country) stat(n mean sd) columns(stat)
tabstat mood if class == 2, by(country) stat(n mean sd) columns(stat)
tabstat mood if class == 3, by(country) stat(n mean sd) columns(stat)

* The t-tests in the semi-panneled dataset 

bysort country: ttest mood_poor == mood_mid
bysort country: ttest mood_mid == mood_rich 

ttest mood_poor == mood_mid
ttest mood_mid == mood_rich 


// Table 5: Factor analysis

factor std_fr_poor std_fr_mid std_fr_rich
factor std_de_poor std_de_mid std_de_rich
factor std_gb_poor std_gb_mid std_gb_rich
factor std_nl_poor std_nl_mid std_nl_rich
factor std_no_poor std_no_mid std_no_rich
factor std_se_poor std_se_mid std_se_rich
factor std_ch_poor std_ch_mid std_ch_rich

factor std_fr_poor std_de_poor std_gb_poor std_nl_poor std_no_poor std_se_poor std_ch_poor
factor std_fr_mid std_de_mid std_gb_mid std_nl_mid std_no_mid std_se_mid std_ch_mid
factor std_fr_rich std_de_rich std_gb_rich std_nl_rich std_no_rich std_se_rich std_ch_rich


// Figure 3: ANOVA

* Variance associated to time (R-sq)

anova mood year if class != 0 // .145
anova mood year if country==1 & class != 0 // France (.556)
anova mood year if country==2 & class != 0 // Germany (.372)
anova mood year if country==3 & class != 0 // Great Britain (.634)
anova mood year if country==4 & class != 0 // Netherlands (.593)
anova mood year if country==5 & class != 0 // Norway (.271)
anova mood year if country==6 & class != 0 // Sweden (.439)
anova mood year if country==7 & class != 0 // Switzerland (.241)

* Variance associated to income group

anova mood class if class != 0 // .277
anova mood class if country==1 & class != 0 // France (.285)
anova mood class if country==2 & class != 0 // Germany (.312)
anova mood class if country==3 & class != 0 // Great Britain (.288)
anova mood class if country==4 & class != 0 // Netherlands (.231)
anova mood class if country==5 & class != 0 // Norway (.551)
anova mood class if country==6 & class != 0 // Sweden (.503)
anova mood class if country==7 & class != 0 // Switzerland (.271)

* Variance associated to country

anova mood country if class != 0 // .102

*Graph ANOVA

twoway (scatter income time, mlabel(country) mlabposition(6)), scheme(plottig) 


// Figure 4: Polarisation measures

gen std_polar = 1
bysort country year (class): replace std_polar = (std_classmood[2] - std_classmood[4]) 
label variable std_polar "Polarisation measure"

gen std_polar_abs = abs(std_polar)
label variable std_polar_abs "Polarisation measure (absolute values)"

graph twoway (line std_polar year, sort) (lfit std_polar year, sort), ytitle(Polarisation of redistribitive preferences, size(vsmall)) by(country) scheme(plottig) legend(size(vsmall) position(6)) xlabel(1975(5)2015, angle(45) labsize(vsmall)) 

reg std_polar year if country==1 // .04
reg std_polar year if country==2 // .00
reg std_polar year if country==3 // .02
reg std_polar year if country==4 // -.01
reg std_polar year if country==5 // .01
reg std_polar year if country==6 // -.02
reg std_polar year if country==7 // -.02


// Table 7: Regression Models

recode country (1 3 4 5 6 7=1 "Others") (2=0), gen(nogermany) 
xtreg std_mood_mid l.std_mood_mid std_mood_poor, fe // (1)
est sto mo1
xtreg std_mood_mid l.std_mood_mid std_mood_rich, fe // (2)
est sto mo2
xtreg std_mood_mid l.std_mood_mid std_mood_poor std_mood_rich, fe // (3)
est sto mo3
xtreg d.std_mood_mid l.std_mood_mid d.std_mood_poor d.std_mood_rich, fe // (4)
est sto mo4
reg d.std_mood_mid l.std_mood_mid d.std_mood_poor d.std_mood_rich if country==2 // (6)
est sto germany
xtreg d.std_mood_mid l.std_mood_mid d.std_mood_poor d.std_mood_rich if nogermany==1, fe // (7)
est sto nogermany

est tab mo1 mo2 mo3 mo4 germany nogermany, b(%5.2f)  star


// Table 7: Regression Models (with lagged rich and poor)

recode country (1 3 4 5 6 7=1 "Others") (2=0), gen(nogermany) 
xtreg std_mood_mid l.std_mood_mid l.std_mood_poor, fe // (1)
est sto mo1
xtreg std_mood_mid l.std_mood_mid l.std_mood_rich, fe // (2)
est sto mo2
xtreg std_mood_mid l.std_mood_mid l.std_mood_poor l.std_mood_rich, fe // (3)
est sto mo3
xtreg d.std_mood_mid l.std_mood_mid l.d.std_mood_poor l.d.std_mood_rich, fe // (4)
est sto mo4
reg d.std_mood_mid l.std_mood_mid l.d.std_mood_poor l.d.std_mood_rich if country==2 // (6)
est sto germany
xtreg d.std_mood_mid l.std_mood_mid l.d.std_mood_poor l.d.std_mood_rich if nogermany==1, fe // (7)
est sto nogermany

est tab mo1 mo2 mo3 mo4 germany nogermany, b(%5.2f)  star



